import React,{Component} from 'react'

   import {getTarget,getStockComment} from '../../../api/index.js'
   import  './tabslist.less'
class  TabsList extends Component{
    constructor(props){
          super(props)
          this.state={
               code:"688051",
               dot:[],
               contructCode:[]
          }
    }
    componentWillMount(){
         let params={
            tagId:6,
            isRecommend:0,
            beginNumber:0,
            count:15
         }
         getTarget(params).then((res)=>{
            this.setState({
               dot:res.mdata.dtos
            })
            this.dealContructCode(res.mdata.dtos);
         })
    }
    componentDidMount(){
        console.log("did mount")
    }
    componentDidCatch(){
        console.log('did catch')
    }
    componentDidUpdate(){
        console.log('update did')
        console.log(this.state.dot)
    }
    componentWillUnmount(){
        console.log("unmmount")
    }
    dealContructCode=(arr)=>{
        let stockArrList= arr.map(item=>{
            return {
                "stockCodeInternal":item.stockCodeInternal,
                "tradeMins":item.tradeMins
            }
        })
        this.getStockComment(stockArrList);
    }
    getStockComment=(arr)=>{
       getStockComment(arr).then(res=>{
          if(res.result==1){
              var ldata=res.ldata;
              ldata.map(item=>{
                  if(item.updated){
                  let dots= this.state.dot.map(items=>{
                        if(items.stockCodeInternal===item.stockCodeInternal){
                           return item
                        }
                        return item
                      })
                      this.setState({
                          dot:dots
                      })
                    console.log(item,dots)
                  }
              })
          }
       })
    }
    render(){
        const {targetId} =this.props;
        const {dot}=this.state;
        return(
            <div className="tn-tabs-list">
                <ul>
                    {
                        dot.map((item,i)=>
                            (<li key={i}>
                                    <span>{item.stockCode}</span>
                                    <span>{item.stockName}</span>
                                    <span>{item.latestPrice}</span>
                                    <span>{item.priceChange}</span>
                                    <span>{item.priceChangeRate}</span>
                                    <span>{item.preclosePrice}</span>
                                </li>
                            )
                        )
                    }
                </ul>
            </div>    
        )
    }
} 
export default  TabsList; 